﻿using loginWinForm.dao;
using loginWinForm.entity;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace loginWinForm.service.impl
{
    class CodingService : ICodingService
    {
        private string strcon = ConfigurationManager.ConnectionStrings["connSqlServer"].ToString();
        public List<CodeInfo> GetCodes(Dictionary<string, string> map)
        {
            List<CodeInfo> codes = new List<CodeInfo>();
          
            string sql = "SELECT [id] ,[coding] ,[ide] ,[book] ,[creater] ,[createName] ,[createTime] ,[updater] ,[updateName] ,[updateTime] " +
                            "FROM CODE_INFO ";
            if (map.Count() > 0)
            {
                sql += " WHERE ";
                if (map.ContainsKey("book"))
                {
                    sql += " book Like '%" + map["book"] + "%'";
                }
                if (map.ContainsKey("coding"))
                {
                    sql += " coding Like '%" + map["coding"] + "%'";
                }
            }
            sql += " ORDER BY [updateTime] DESC ";
            DataSet ds = CommonSQLDao.GetDataSet(sql);
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                CodeInfo code = new CodeInfo();
                code.Id = null == row["id"] ? "" : row["id"].ToString();
                code.Coding = null == row["coding"] ? "" : row["coding"].ToString();
                code.Ide = null == row["ide"] ? "" : row["ide"].ToString();
                code.Book = null == row["book"] ? "" : row["book"].ToString();
                code.Creater = null == row["creater"] ? "" : row["creater"].ToString();
                code.CreateName = null == row["createName"] ? "" : row["createName"].ToString();
                code.CreateTime = null == row["createTime"] ? "" : row["createTime"].ToString().ToString();
                code.Updater = null == row["updater"] ? "" : row["updater"].ToString();
                code.UpdateName = null == row["updateName"] ? "" : row["updateName"].ToString();
                code.UpdateTime = null == row["updateTime"] ? "" : row["updateTime"].ToString();
                codes.Add(code);
            }

            return codes;
        }
    }
}
